package com.travelsky.airchina.boarding.web.interceptor;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.travelsky.airchina.boarding.common.ConstType;

public class SessionCheckInterceptor extends HandlerInterceptorAdapter {
	@SuppressWarnings("unchecked")
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		String className = handler.getClass().getName();
		/**
		 * 管理后台的请求都要登录
		 */
		if(className!=null && className.indexOf("com.travelsky.airchina.boarding.web.admin")!=-1){
			if(request.getSession().getAttribute(ConstType.ADMIN_SESSION_USER)!=null){
				/**
				return true;
				*/
//				Map<String,String> userOperationUriMap = (Map<String,String>)request.getSession().getAttribute(ConstType.USER_OPERATION_URIS_MAP);
//				String requestURI = request.getRequestURI();
//				if(userOperationUriMap!=null && userOperationUriMap.keySet().size()>0){
//					boolean isAuth = false;
//					for(String uri:userOperationUriMap.keySet()){
//						if(requestURI!=null && requestURI.indexOf(uri)!=-1){
//							isAuth = true;
//							break;
//						}
//					}
//					if(isAuth){
//						return true;
//					}else{
//						response.sendRedirect(request.getContextPath()+"/system/noauthority");
//						return false;
//					}
//				}else{
//					response.sendRedirect(request.getContextPath()+"/system/noauthority");
//					return false;
//				}
				return true;
			}else{
				response.sendRedirect(request.getContextPath()+"/system/login");
				return false;
			}
		}else{
			return true;
		}
	}
}
